-
Notifications
You must be signed in to change notification settings - Fork 439
Add conformsTo argument to member macro expansion operation #2004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add conformsTo argument to member macro expansion operation #2004
Conversation
@swift-ci please test |
a0a6ce8
to
6ff4a07
Compare
@@ -236,6 +236,7 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext> | |||
let members = try attachedMacro.expansion( | |||
of: attributeNode, | |||
providingMembersOf: declGroup, | |||
missingConformancesTo: conformanceList?.map(\.type) ?? [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this parameter called missingConformancesTo:
? AFAICT you are passing in the existing conformances, not some list of missing conformances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm struggling mightily to name this. Let's discussion naming over at https://forums.swift.org/t/pitch-member-macros-that-know-what-conformances-are-missing/66590
@swift-ci please test |
1 similar comment
@swift-ci please test |
8d1c176
to
f1eaeec
Compare
@swift-ci please test |
@swift-ci please clean test |
cf38182
to
d3a820a
Compare
@swift-ci please test |
… operation Stage in an entrypoint for member macros that allows them to learn about which conformances that they've asked about are "missing", meaning that they are not present on the type (ignoring those that would be generated by an extension macro). This information is equivalent to the information provided to extension macros, although the member macro itself cannot create the conformance.
d3a820a
to
5ff03e2
Compare
@swift-ci please test |
@swift-ci please test Windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add the API change to the release notes and add a test case for it?
public extension MemberMacro { | ||
/// Default implementation supplies no conformances. | ||
static func expansion( | ||
of node: AttributeSyntax, | ||
providingMembersOf declaration: some DeclGroupSyntax, | ||
in context: some MacroExpansionContext | ||
) throws -> [DeclSyntax] { | ||
return try expansion(of: node, providingMembersOf: declaration, conformingTo: [], in: context) | ||
} | ||
|
||
/// Default implementation that ignores the unhandled conformances. | ||
static func expansion( | ||
of node: AttributeSyntax, | ||
providingMembersOf declaration: some DeclGroupSyntax, | ||
conformingTo protocols: [TypeSyntax], | ||
in context: some MacroExpansionContext | ||
) throws -> [DeclSyntax] { | ||
return try expansion(of: node, providingMembersOf: declaration, in: context) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think adding default implementations that forward in both directions is a good way. If I write the following,
public struct X: MemberMacro {}
it compiles just fine without any error that I’m missing any protocol requirement and the call to the expansion function will just infinitely recurse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can stage out one of them, but for now I want forward/backward compatibility.
I can do this in a follow-up |
Stage in an entrypoint for member macros that allows them to learn about which conformances that they've asked about are "missing", meaning that they are not present on the type (ignoring those that would be generated by an extension macro). This information is equivalent to the information provided to extension macros, although the member macro itself cannot create the conformance.